﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AccountControl
{
    struct Amount : IComparable
    {
        private int value;
        private string currency;

        public int Value 
        {
            get { return value; }
            set { this.value = value; }
        }

        public string Currency
        {
            get { return currency; }
            set { this.currency = value; }
        }

        public Amount(int value, string currency)
        {
            this.value = value;
            this.currency = currency;
        }

        public int CompareTo(object comparableAmount)
        {
            try
            {
                Amount amount = (Amount)comparableAmount;
                return this.value - amount.value;
            }
            catch (Exception e)
            {
                throw new ArgumentException("Object is not an Amount!", e);
            }
        }

        public override string ToString()
        {
            string stringToReturn = this.value + " " + this.currency;
            return stringToReturn;
        }

        public static Amount Parse(string amount)
        {
            try
            {
                string[] splittedAmount = amount.Split(' ');
                int amountValue = int.Parse(splittedAmount[0]);
                string amountCurrency = splittedAmount[1];
                return new Amount(amountValue, amountCurrency);
            }
            catch (Exception e)
            {
                throw new FormatException("Input string was not in a correct format.", e);
            }
        }
    }

    struct BulgarianDate : IComparable
    {
        private DateTime UniversalDate;
        private bool showTime;

        public bool ShowTime
        {
            get { return showTime; }
            set { showTime = value; }
        }

        public BulgarianDate(DateTime date, bool showTime) 
        {
            UniversalDate = date;
            this.showTime = showTime;
        }

        public BulgarianDate(DateTime date)
        {
            UniversalDate = date;
            this.showTime = false;
        }

        public DateTime Date
        {
            get
            {
                return UniversalDate;
            }
        }

        public int CompareTo(object comparableBulgarianDate)
        {
            try
            {
                BulgarianDate date = (BulgarianDate)comparableBulgarianDate;
                return this.UniversalDate.CompareTo(date.Date);
            }
            catch (Exception e)
            {
                throw new ArgumentException("Object is not a BulgarianDate!", e);
            }
        }

        public override string ToString()
        {
            if (showTime)
            {
                return this.UniversalDate.ToString("dd/MM/yyyy hh:mm:ss");
            }
            else
            {
                return this.UniversalDate.ToString("dd/MM/yyyy");
            }
        }

        public string ToString(string format)
        {
            return this.UniversalDate.ToString(format);
        }

        public static BulgarianDate Parse(string date) 
        {
            try
            {
                if (!date.Contains("-"))
                {
                    string[] splittedDate = date.Split('/');
                    string universalDate = splittedDate[1] + "/" + splittedDate[0] + "/" + splittedDate[2];
                    return new BulgarianDate(DateTime.Parse(universalDate));
                }
                else 
                {
                    string[] splittedDate = date.Split('/', ' ', ':');
                    string universalDate = splittedDate[1] + "/" + splittedDate[0] + "/" + splittedDate[2] +
                        " " + splittedDate[3] + ":" + splittedDate[4] + ":" + splittedDate[5];
                    return new BulgarianDate(DateTime.Parse(universalDate));
                }
            }
            catch (Exception e) 
            {
                throw new FormatException("Input string was not in a correct format.", e);
            }
        }
    }
}
